
var Transform = require('pipestream').Transform;

exports.name="cyc custom fun";
exports.dealResponse = function(res,req) {
  dealXMYPRes(res,req);
  // if(req.curUrl.indexOf("unauth/sys-workbench/list")!=-1 || req.curUrl.indexOf("center/admin/list")!=-1){
  //   console.info("cyctest")
  //   console.info(req)
  // }

  
  // res.setHeader('access-control-allow-origin', "*");
  // res.setHeader('access-control-allow-credentials', true);

  //处理返回结果
  // var __transform = new Transform();
  // __transform._transform = function(text, encoding, callback) {

  //   text = "cyctest++++++++++++"+text;
  //   callback(null, text);
  // };
  // res.addTextTransform(__transform);
};

exports.dealRequest = function(req) {
  var a = 1;
};

function dealXMYPRes(res,req){
  if(req.curUrl.indexOf("/mtop/act/orderspike/getActInfo")!=-1){
    var __transform = new Transform();
    __transform._transform = function(text, encoding, callback) {
      try{
        if(text){
          var json = JSON.parse(text);
          console.info("preText:"+text);
          if(json.data && json.data.actStatusInfo){
            json.data.userStatusInfo.ordered = true;
            json.data.actStatusInfo.spikeLeftTime = json.data.actStatusInfo.spikeLeftTime - 10400;
          }
    
          text = JSON.stringify(json);
          console.info("newText:"+text);
        }
      }catch(ex){

      }
      callback(null, text);
    };
    res.addTextTransform(__transform);
  }

}

